<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="page" uri="http://page/zrgk/fourth"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<link href="houtai/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="houtai/js/main.js"></script>
<script type="text/javascript" src="houtai/pages/js2/WdatePicker.js"></script>
<script type="text/javascript">
//单个删除
function delButton(){
	if(confirm("你确定要删除吗？")){
		alert("删除成功！");
	}
}
function resp(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
		var txt=xmlhttp.responseText;	
		 
		location.href="NewsServlet?param="+"selectAll";
}

}
//批量删除
function checkeDel(){
	var count=0;
	var list=new Array();
	var alls=document.getElementsByName("checkid");
			for(var i=0;i<alls.length;i++){
				if(alls[i].checked){
				list[count]=alls[i].value;
					count++;
				}		
			}
			if(count>0){
			
				if(confirm("确认要删除吗?")){
					xmlhttp=new XMLHttpRequest();
					xmlhttp.onreadystatechange=resp;
					xmlhttp.open("get","NewsServlet?id="+list+"&param="+"alldelete", true);
					xmlhttp.send(null);
					//alert("删除成功!");
					 document.getElementById("allde").submit();
				}
				
			}else{
				alert("请选中要操作的项");
			}
}

//导出excel
	function expolExcel() {

	var count=new Array();
	var index=0;
	var alls = document.getElementsByName("checkid");
	for ( var i = 0; i < alls.length; i++) {
		if (alls[i].checked) {
			count[index]=alls[i].value;;
			index++;
		}
	}
	if (count.length>0) {
	
		   location.href="TestServlet?param=news&newsid="+count+"&time="+new Date().getTime();
		  
	}else {
		alert("请选中要操作的项");
	}
	
}
//修改新闻状态
function updateState(node,newid){
     xmlhttp=new XMLHttpRequest();
	 xmlhttp.onreadystatechange=res1;

	if(node.checked){
		xmlhttp.open("get", "NewsServlet?param="+"updatestate"+"&state="+1+"&newid="+newid, true);
		//location.href="NewsServlet?method="+"updatestate"+"&state="+1+"&newid="+newid;	
	}else{
	    xmlhttp.open("get", "NewsServlet?param="+"updatestate"+"&state="+0+"&newid="+newid, true);
		//location.href="NewsServlet?method="+"updatestate"+"&state="+0+"&newid="+newid;	
	}
	 xmlhttp.send(null); 

}


function res1(){
	if(xmlhttp.readyState==4&&xmlhttp.status==200){
		var txt=xmlhttp.responseText;
		alert(txt);
	}
}

//全选和全不选
function allCheck(){
	var alls=document.getElementsByName("checkid");
	var conterCheck=document.getElementById("checkbox1");
	for(var i=0;i<alls.length;i++){
		if(conterCheck.checked){
			alls[i].checked=true;
		}else{
			alls[i].checked=false;
		}
	}
}
//全选后某个按钮取消选中,则全选按钮也取消选中
	function check(node) {
		var conterCheck = document.getElementById("checkbox1");
		if (!node.checked) {
			if (conterCheck.checked) {
				conterCheck.checked = false;
			}
		}

	}
function sub(){

document.ne.submit();

}


	function init() {
		if (<%=session.getAttribute("states") != null%>)
	
			document.getElementById("select2").value =<%=session.getAttribute("states")%>
	}
	window.onload = init;
</script>
</head>
<body>


	<table width="100%" height="100%" border="0" cellspacing="0"
		cellpadding="3">
		<tr>
			<td style="height:25px; background-color:#f3f3f3; font-weight:bold"
				valign="top">&nbsp;&nbsp;&nbsp;&nbsp;当前位置： <img
				src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;soda创业教育平台&nbsp;&nbsp;
				<img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;后台管理&nbsp;&nbsp;
				<img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;新闻管理
			</td>
		</tr>
		<tr>
			<td
				style="height:34px; background-image:url(houtai/images/main_header.gif); border-bottom:1px solid #cfd8e0; padding:0px">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="20" height="34"><img
							src="houtai/images/main_headerL.gif" width="20" height="34"></td>
						<td style="color:#90c8e8;"><img
							src="houtai/images/icon_card.gif" width="16" height="16"
							align="absmiddle">&nbsp;&nbsp;<strong>新闻管理</strong></td>
						<td align="right" class="white" style="padding-right:20px"><a
							href="Javascript:expolExcel()" class="barBtn"><img
								src="houtai/images/1.png" width="16" height="16"
								align="absmiddle"> 导出</a> 
								 
								
								<a
							href="houtai/pages/newconter/add.jsp" class="barBtn"><img
								src="houtai/images/5.png" width="16" height="16"
								align="absmiddle"> 添加</a> <a href="Javascript:checkeDel()"
							class="barBtn"><img src="houtai/images/6.png" width="16"
								height="16" align="absmiddle"> 删除</a></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td
				style="height:30px; background-color:#bddbff; border-bottom:1px solid #cfd8e0;"><table
					width="100%" border="0" cellpadding="3" cellspacing="1"
					class="table1">
					<form action="NewsServlet" method="post" name="ne">
						<input type="hidden" name="param" value="selectAll" />
						<TR>
							<th width="10%" align="center">标题</th>
							<td width="20%" class="BGCgray"><input type="text"
								name="newTitle" id="textfield"
								value="${sessionScope.sn.newtitle}"></td>
							<th width="10%" align="center">更新时间</th>
							<td width="20%" class="BGCgray"><input type="text"
								name="updateTime" id="textfield" class="Wdate"
								onClick='WdatePicker({dateFmt:&quot;yyyy-MM-dd&quot;});'
								value="${sessionScope.sn.updatetime}"></td>
							<th width="10%" align="center">是否推荐</th>
							<td width="20%" class="BGCgray"><select name="select2"
								id="select2">

									<option value="2"
										${sessionScope.sn.state==2?"selected='selected'":"" }>全部</option>
									<option value="1"
										${sessionScope.sn.state==1?"selected='selected'":"" }>是</option>
									<option value="0"
										${sessionScope.sn.state==0?"selected='selected'":"" }>否</option>
							</select></td>
							<th width="10%" align="center">
								<BUTTON style="HEIGHT:25px"
									onClick="javascript:location.href='NewsServlet?param=selectAll'">
									<img src="houtai/images/btn_search.gif" width="16" height="16"
										align="absmiddle"> 查询
								</BUTTON>
							</th>
						</TR>
					</form>
				</table></td>
		</tr>
		<tr>
			<td height="100%" valign="top">
				<div style="overflow:auto;height:100%; width:100%">
					<table width="100%" border="0" cellpadding="3" cellspacing="1"
						class="table1">
						<TR>
							<th align="center"><input type="checkbox" name="checkbox"
								id="checkbox1" onChange="allCheck()"></th>
							<th align="center">ID</th>
							<th align="center">信息标题</th>
							<th align="center">发布时间</th>
							<th align="center">是否推荐</th>
							<th width="180" align="center">操作</th>
						</TR>


						<TR>
							<form action="NewsServlet" method="post" name="sel">
								<input type="hidden" name="param" value="selectAll" />

								<c:forEach items="${news}" var="n" varStatus="i">
									<c:if test="${n.newDelete!=0 }">

										<TD align="center"><input type="checkbox"
											value="${n.newId }" name="checkid" onclick="check(this)"></TD>
										<TD align="center">${ (page.page-1)*page.per+i.index+1}</TD>
										<TD align="left">
										<a href="NewsServlet?param=show&id=${n.newId}"
											style="color:black;">${n.newTitle}</a></TD>
										<TD align="center">${n.newTime}</TD>
										<TD align="center"><input type="checkbox"
											name="checkbox3"  onclick="updateState(this,${n.newId})"
											<c:if test="${n.newState==1}">checked="checked"</c:if> /></TD>
							</form>

							<TD width="180" align="center">
								<BUTTON style="height:21px; font-size:12px"
									onClick="javascript:if (confirm('编辑该信息？')) location.href='NewsServlet?editId=${n.newId}&param=edit';else return;">编辑</BUTTON>
								<BUTTON style="height:21px; font-size:12px"
									onClick="javascript:if (confirm('删除该信息？'))location.href='NewsServlet?newId=${n.newId}&param=delete';else return;">删除</BUTTON>
							</TD>
						</TR>
						</c:if>
						</c:forEach>


					</table>
					<page:page pi="${page }" />
				</div>
			</td>
		</tr>
	</table>

</body>
</html>